package exp1.test2;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by 春旺 on 2017/9/24.
 */
public class mergeSortedList {
    public static List<? extends Comparable> mergeSortedArrayList
            (List<? extends Comparable> aList,
             List<? extends Comparable> bList){
        ArrayList array = new ArrayList();
        if (aList.size() >= bList.size()) {
            for (int i = 0;i < aList.size();i ++){
                array.add(aList.get(i));
                for (int j= 0;j<bList.size();j++){

                    if (aList.get(i).compareTo(bList.get(j)) < 0){
                        array.add(bList.get(j));
                        break;
                    }
                }
            }
        }
        else {
            for (int i = 0;i < bList.size();i ++){
                array.add(bList.get(i));
                for (int j= 0;j<bList.size();j++){

                    if (aList.get(i).compareTo(bList.get(j)) < 0){
                        array.add(aList.get(j));
                        break;
                    }
                }
            }
        }
return array;

    }
    public static List<? extends Comparable> SortedLinkedList
            (List<? extends Comparable> aList,
             List<? extends Comparable> bList){
        LinkedList array = new LinkedList();
        if (aList.size() >= bList.size()) {
            for (int i = 0;i < aList.size();i ++){
                array.add(aList.get(i));
                for (int j= 0;j<bList.size();j++){

                    if (bList.get(i).compareTo(aList.get(j)) < 0){
                        array.add(bList.get(j));
                        break;
                    }
                }
            }
        }
        else {
            for (int i = 0;i < bList.size();i ++){
                array.add(bList.get(i));
                for (int j= 0;j<bList.size();j++){

                    if (aList.get(i).compareTo(bList.get(j)) < 0){
                        array.add(aList.get(j));
                        break;
                    }
                }
            }
        }

return array;
    }


}
